﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Disposition : System.Web.UI.UserControl
{

    //public static string connString = "user id=portaluser;data source=172.25.9.26;initial catalog=VoiceNet_Focus;password=sqluser";

    //public SqlConnection conn = new SqlConnection(connString);

    protected void Page_Load(object sender, EventArgs e)
    {

        Response.Expires = -1;


        if (!IsPostBack)
        {
            try
            {
                ddlDispo.DataSource = ((DataAccess)Session["App"]).GetUsercodes();
                ddlDispo.DataTextField = ((DataAccess)Session["App"]).GetUsercodes().Columns["textField"].ColumnName.ToString();
                ddlDispo.DataValueField = ((DataAccess)Session["App"]).GetUsercodes().Columns["usercode"].ColumnName.ToString();
                ddlDispo.DataBind();
                ddlDispo.Items.Insert(0, new ListItem("", ""));
            }
            catch
            {
                ddlDispo.Items.Insert(0, new ListItem("Unable to get dispos", "Unable to get dispos"));
            }
            //LoadUsercodes();
        }
        else
        {
            //Session["App"] = App;
            //App = (DataAccess)Session["App"];
        }

    }

    //protected void Page_Unload(
    protected void ddlDispo_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            ((DataAccess)Session["App"]).PutCallData("webusercode", ddlDispo.SelectedItem.Value);
            //((DataAccess)Session["App"]).PutResult("webusercode", ddlDispo.SelectedItem.Value);
            ((DataAccess)Session["App"]).CommitCallData();
            //((DataAccess)Session["App"]).CommitResult();

            //Session["App"] = App;
            //UpdateResult();
        }
        catch
        {
        }
    }

    //private void LoadUsercodes()
    //{
    //    SqlDataAdapter ProductTypesDA = default(SqlDataAdapter);
    //    DataSet ProductTypesDS = default(DataSet);

    //    connString = "user id=portalUser;data source=" + Session["servername"] + ";initial catalog=" + Session["projectname"] + ";password=sqluser";
    //    conn.ConnectionString = connString;

    //    System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
    //    string lccommand = null;

    //    lccommand = "exec f_GetUserCodesForAgent '" + Session["campaignname"].ToString() + "' ";

    //    ProductTypesDA = new SqlDataAdapter(lccommand, conn);
    //    ProductTypesDS = new DataSet();
    //    ProductTypesDA.Fill(ProductTypesDS, "AllTables");
    //    //ddlProductTypes.DataSource = ProductTypesDS;
    //    ddlDispo.DataSource = ProductTypesDS.Tables[0];
    //    ddlDispo.DataTextField = ProductTypesDS.Tables[0].Columns["textField"].ColumnName.ToString();
    //    ddlDispo.DataValueField = ProductTypesDS.Tables[0].Columns["usercode"].ColumnName.ToString();
    //    ddlDispo.DataBind();
    //    ddlDispo.Items.Insert(0, new ListItem("", ""));
    //    //ddlProductTypes.SelectedIndex = 0;
    //}

    //public void UpdateResult()
    //{
    //    string lccommand = null;
    //    SqlCommand command = new SqlCommand();


    //    ////get product data from product table
    //    connString = "user id=portalUser;data source=" + Session["servername"] + ";initial catalog=" + Session["projectname"] + ";password=sqluser";
    //    conn.ConnectionString = connString;
    //    conn.Open();
    //    lccommand = "update result set webusercode = '" + ddlDispo.SelectedValue + "' where enterpriselistid = " + Session["listid"] + " ";
    //    command.CommandType = CommandType.Text;
    //    command.CommandText = lccommand;
    //    command.Connection = conn;

    //    if (command.ExecuteNonQuery() == 1)
    //    {
    //        //it worked
    //    }
    //    else
    //    {
    //        //it didn't work
    //    }
    //    conn.Close();

    //}
}